1. /* sdfcosSR.cpp by K.Tsuru */
  2. // function ID 3104 DRADIX
  3. /*****************************
  4. SDouble class
  5. trigonometric function cos x
  6. using sereies and reduction method
  7. enum { COS_CALC = 1, SIN_CALC = 2, TAN_CALC = 3, COT_CALC = 4};
  8. ******************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. #define usesCosSeriesInCos 1
  13. SDouble CosS_RN(const SDouble& x){
  14. if(x.Sign(3104) == 0) return 1.0; // x = 0
  15. #if usesCosSeriesInCos
  16. // |x| is very small.
  17. if(x.NetRdxExp() < -4) return CosSeries(x); // |x| < 1.0e-16 ver.2.18
  18. uint fig = x.Last() - x.First() +1u;
  19. double c;
  20. if(fig <= 5u){ // x is a short number.
  21. double dblX = doubleD(x, 0), absX = fabs(dblX);
  22. // y is short and small, then call CosSeries()
  23. c = (absX > M_PI_4) ? 1.0 : log10((double)x.MaxSize()*absX) - 2.5;
  24. if(c < 0) return CosSeries(x);
  25. }
  26. #endif
  27. SDouble y, r;
  28. int func = COS_CALC;
  29. int sgn = GetTriCalcMethod(x, y, &func); // |y| < pi/4
  30. if(sgn == 0){ // y = -1, 0, 1
  31. x.upToTerm = 0;
  32. return y;
  33. }
  34. #if usesCosSeriesInCos
  35. // y is long but small.
  36. double dblY = doubleD(y, 0), absY = fabs(dblY);
  37. c = (double)x.MaxSize()/64 + log10(absY) + 0.5;
  38. if(c < 0){
  39. if(func == COS_CALC) r = CosSeries(y);
  40. else r = SinSeries(y);
  41. goto Ret;
  42. }
  43. #endif
  44. //RN : using x/R^n reduction method
  45. if(func == COS_CALC) r = CosRN(y);
  46. else r = SinRN(y);
  47. Ret:
  48. if(sgn < 0) r.ChangeSign(); // r = -r;
  49. return r;
  50. }

sdfcosSR.cpp : last modifiled at 2017/09/03 16:01:42(1,440 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).